package com.xmutca.sso.dao;

import com.xmutca.core.mybatis.MyBatisDao;
import com.xmutca.core.mybatis.lang.MybatisExtendedLanguageDriver;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-08-29 15:53
 */
@MyBatisDao
public interface UserRoleDao {

    /**
     * 用户角色新增
     * @param user
     * @param role
     * @return
     */
    @Insert("insert into t_sys_user_role(user, role) values(#{user}, #{role})")
    int add(@Param("user") String user, @Param("role") Integer role);

    /**
     * 用户角色删除
     * @param user
     * @param role
     * @return
     */
    @Delete("delete t_sys_user_role where user = #{user} and role = #{role}")
    int del(@Param("user") String user, @Param("role") Integer role);

    /**
     * 用户角色删除，根据用户删除
     * @param user
     * @return
     */
    @Delete("delete t_sys_user_role where user = #{user}")
    int delByUser(String user);

    /**
     * 用户角色批量删除，根据用户删除
     * @param users
     * @return
     */
    @Lang(MybatisExtendedLanguageDriver.class)
    @Delete("delete t_sys_user_role where user in (#{users})")
    int batchDelByUser(List<String> users);

    /**
     * 用户角色删除，根据角色删除
     * @param role
     * @return
     */
    @Delete("delete t_sys_user_role where role = #{role}")
    int delByRole(Integer role);

    /**
     * 用户角色删除, 根据用户 + 角色
     * @param user
     * @param roles
     * @return
     */
    @Lang(MybatisExtendedLanguageDriver.class)
    @Delete("delete t_sys_user_role where user = #{user} and role in (#{roles})")
    int delByUserRoles(@Param("user") String user, @Param("roles") List<Integer> roles);

    /**
     * 用户角色批量删除，根据角色删除
     * @param role
     * @return
     */
    @Lang(MybatisExtendedLanguageDriver.class)
    @Delete("delete t_sys_user_role where role in (#{roles})")
    int batchDelByRole(@Param("roles") List<Integer> roles);
}
